package com.xk.demo.menu.controller;

import com.xk.demo.common.control.BaseController;
import com.xk.demo.menu.service.MenuService;
import com.xk.demo.mybatis.entity.PtMenuI18nEntity;
import com.xk.demo.mybatis.ztree.ZtreeEntity;
import org.apache.logging.log4j.LogManager;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.function.Supplier;
import java.util.logging.Logger;

@Controller
@RequestMapping("/menu")
public class MenuController extends BaseController {
    private org.apache.logging.log4j.Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private MenuService menuService;
    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/menuPage")
    public String menuPage(){
        return "menu/menuPage";
    }
    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/getMenuTree")
    @ResponseBody
    public List<ZtreeEntity> getMenuTree(){
        return menuService.getMenuTree();
    }


    @RequestMapping("/getI18nByMenuId")
    @ResponseBody
    public List<PtMenuI18nEntity> getI18nByMenuId(HttpServletRequest request){
        String menuId = request.getParameter("menuId");
        logger.info("menuId:" +  menuId);
        List<PtMenuI18nEntity> list = menuService.getI18nByMenuId(menuId);
        return list;
    }

    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/saveI18nData")
    @ResponseBody
    public String saveI18nData(PtMenuI18nEntity entity){
        Logger logger = null;
        logger.info((Supplier<String>) entity);
        menuService.saveI18nData(entity);
        return getSuccessMsg("menu.save.i18n.success");
    }

    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/addI18nData")
    @ResponseBody
    public String addI18nData(PtMenuI18nEntity entity){
        Logger logger = null;
        logger.info((Supplier<String>) entity);
        menuService.addI18nData(entity);
        return getSuccessMsg("menu.add.i18n.success");
    }
    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/deleteI18nData")
    @ResponseBody
    public String deleteI18nData(PtMenuI18nEntity entity){
        Logger logger = null;
        logger.info((Supplier<String>) entity);
        menuService.deleteI18nData(entity);
        return getSuccessMsg("menu.delete.i18n.success");
    }

    private String getSuccessMsg(String s) {
        return s;
    }




}


